import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:qaun_ni_dev/provider/temp_provider.dart';

class ProviderSelectPage extends StatefulWidget {
  @override
  _ProviderSelectPageState createState() => _ProviderSelectPageState();
}

class _ProviderSelectPageState extends State<ProviderSelectPage> {
  @override
  Widget build(BuildContext context) {
    print('会不会被加载一次');
    return Scaffold(
      appBar: AppBar(
        title: Text('23333'),
      ),
      body: ListView(
        children: <Widget>[
          Consumer<TempProvider>(
              builder: (context,data,_){
                print('打印输出number11111111的值');
                return Text('${data.number1}');
              },
          ),
          Consumer<TempProvider>(
            builder: (context,data,_){
              print('打印输出number222222222的值');
              return Text('${data.number2}');
            },
          ),
          Selector(
            builder: (context,data,_) {
              print('是否会打印除这个呢 333333');
              return Text('${data.toString()}selector>>10');
            },
            selector: (context,TempProvider tempProvider) {
              return tempProvider.number1;
          },
          ),
          RaisedButton(
            child: Text('触发增加number1'),
            onPressed: () {
              Provider.of<TempProvider>(context,listen: false).addNumber1();
            },
          ),
          RaisedButton(
            child: Text('触发增加number2'),
            onPressed: () {
              Provider.of<TempProvider>(context,listen: false).addNumber2();
            },
          ),
        ],
      ),
    );
  }
}
